/**
 * @copyright 2017 Indie Semiconductor.
 *
 * This file is proprietary to Indie Semiconductor.
 * All rights reserved. Reproduction or distribution, in whole
 * or in part, is forbidden except by express written permission
 * of Indie Semiconductor.
 *
 * @file gpio_device.h
 */

#ifndef __GPIO_DEVICE_H__
#define __GPIO_DEVICE_H__

#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "rugby.h"
#include "errno.h"

#include "gpioa_sfr.h"

/***************
GPIO1           ->GAP4
GPIO2           ->GAP3
GPIO3           ->GAP1
GPIO4(RXD)      ->GAP0
GPIO5(TXD)      ->GAP2
******/

typedef enum{
  GPIO_PORT_1 = 4,
  GPIO_PORT_2 = 3,
  GPIO_PORT_3 = 1,
  GPIO_PORT_4 = 0,
  GPIO_PORT_5 = 2,
}GpioPort_t;


typedef enum{
  GPIO_DIR_INPUT  = 0,
  GPIO_DIR_OUTPUT = 1,
}GpioDir_t;

typedef enum{
  GPIO_PULL_MODE_PULLUP = 0,
  GPIO_PULL_MODE_PULLDOWN,
  GPIO_PULL_MODE_NONE,
}GpioPullMode_t;


typedef enum{
  GPIO_MUX_GPIO = 0,
  GPIO_MUX_UART  = 1,
}GpioMuxMode_t;



typedef enum{
  GPIO_FALLING_EDGE = 0,
  GPIO_RISING_EDGE = 1,
}GpioISREdge_t;


typedef void (*gpio_cb_func_t)(void);


void GPIO_Init(GpioPort_t port, GpioMuxMode_t muxMode, GpioDir_t stateMode,GpioPullMode_t pullMode);
void GPIO_RegisterIRQ(GpioPort_t port, bool risingEdge, gpio_cb_func_t callback);
void GPIO_UnRegisterIRQ(GpioPort_t port);
void GPIO_Set(GpioPort_t port, bool state);
bool GPIO_Read(GpioPort_t port);
void GPIO_SetPorts(uint8_t portsMask, uint8_t value);
uint8_t GPIO_ReadPorts(uint8_t portsMask);

#endif /* __GPIO_DEVICE_H__ */